<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>

function check(myform){
	function main(myform){
		this.obj=document.myform;
			
	};
	main.prototype={
		user:function(names,box,msg,reg){
			var newobj=this.obj.names;
			var reg=eval(reg)||/^[a-zA-z]\w{3,10}$/;
			newobj.onblur=function(){
				var val=this.value;
				if(reg.test(val)){
					box.innerHTML=msg[0];
					box.style.border='1px solid green';
					box.style.color='green';
					box.style.padding='3px';	
				}else{
					box.innerHTML=msg[1];
					box.style.border='1px solid red';
					box.style.color='red';
					box.style.padding='3px';	
				}	
			};	
		}	
	}
	return new main(myform);	
}


window.onload=function(){
	var spans=document.getElementsByTagName('span');
check('myform').user('names',spans[0],["正确","错误"]);
//check('myform').user('email',spans[1],["正确","错误"],'/fd/');

	
};







</script>
</head>

<body>
<form action="sfs" method="post" name="myform">
用户名：<input type="text" name="names" /><span></span><br />
邮箱：<input type="text" name="email" /><span></span><br />
手机：<input type="text" name="tel" /><span></span><br />
<input type="submit" value="提交"/>
</form>
</body>
</html>
